<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Rooms
 * This class represents a data access object for the database table 'rooms'.
 */
class Rooms {


	private $dao = null;

	private $i = 1;

	/**
	 * associated database field: roomId, type: int, is nullable: false
	 */
	private $roomId  = 0;

	/**
	 * associated database field: roomFloor, type: int, is nullable: true
	 */
	private $roomFloor;

	/**
	 * associated database field: roomFloorCount, type: int, is nullable: true
	 */
	private $roomFloorCount;

	/**
	 * associated database field: hotelId, type: int, is nullable: false
	 */
	private $hotelId  = 0;

	/**
	 * associated database field: roomTypeCode, type: varchar, is nullable: false, character set: utf8, max length: 10
	 */
	private $roomTypeCode;

	/**
	 * associated database field: additionalNotes, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $additionalNotes;

	private $roomfacilitiesArray = null;

	private $roombookingsArray = null;

	private $hotels = null;

	private $roomtypes = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("Rooms");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['roomId'])) $this->roomId = $row['roomId'];
		if(isset($row['roomFloor'])) $this->roomFloor = $row['roomFloor'];
		if(isset($row['roomFloorCount'])) $this->roomFloorCount = $row['roomFloorCount'];
		if(isset($row['hotelId'])) $this->hotelId = $row['hotelId'];
		if(isset($row['roomTypeCode'])) $this->roomTypeCode = $row['roomTypeCode'];
		if(isset($row['additionalNotes'])) $this->additionalNotes = $row['additionalNotes'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Rooms
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'roomId: '.(($escapeQuotationMarks===true) ? addslashes($this->roomId) : $this->roomId).', ';
		$s .= 'roomFloor: '.(($escapeQuotationMarks===true) ? addslashes($this->roomFloor) : $this->roomFloor).', ';
		$s .= 'roomFloorCount: '.(($escapeQuotationMarks===true) ? addslashes($this->roomFloorCount) : $this->roomFloorCount).', ';
		$s .= 'hotelId: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelId) : $this->hotelId).', ';
		$s .= 'roomTypeCode: '.(($escapeQuotationMarks===true) ? addslashes($this->roomTypeCode) : $this->roomTypeCode).', ';
		$s .= 'additionalNotes: '.(($escapeQuotationMarks===true) ? addslashes($this->additionalNotes) : $this->additionalNotes);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Rooms
	 */
	public function toJSONString(){
		$fieldValues = array ("roomId"=>$this->roomId, "roomFloor"=>$this->roomFloor, "roomFloorCount"=>$this->roomFloorCount, "hotelId"=>$this->hotelId, "roomTypeCode"=>$this->roomTypeCode, "additionalNotes"=>$this->additionalNotes);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Rooms object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"rooms\">\n";
		$htmlCode .= '	<div class="rooms_roomId">'.(($escapeHTML===true) ? htmlspecialchars($this->roomId) : $this->roomId)."</div>\n";
		$htmlCode .= '	<div class="rooms_roomFloor">'.(($escapeHTML===true) ? htmlspecialchars($this->roomFloor) : $this->roomFloor)."</div>\n";
		$htmlCode .= '	<div class="rooms_roomFloorCount">'.(($escapeHTML===true) ? htmlspecialchars($this->roomFloorCount) : $this->roomFloorCount)."</div>\n";
		$htmlCode .= '	<div class="rooms_hotelId">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelId) : $this->hotelId)."</div>\n";
		$htmlCode .= '	<div class="rooms_roomTypeCode">'.(($escapeHTML===true) ? htmlspecialchars($this->roomTypeCode) : $this->roomTypeCode)."</div>\n";
		$htmlCode .= '	<div class="rooms_additionalNotes">'.(($escapeHTML===true) ? htmlspecialchars($this->additionalNotes) : $this->additionalNotes)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}


	public static function loadAll(){
		$rooms = new Rooms();
		$rows = $rooms->dao->getData("");
		$roomss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Rooms();
			$d->init($rows[$index]);
			array_push($roomss,$d);
		}
		return $roomss;
	}


	/**
	 * Load the Rooms uniquely by its primary key.
	 * @param hotelId the primary key
	 * @param roomId the primary key
	 * @return Rooms Instance of {@link Rooms}
	 */
	public static function loadUnique($roomId, $hotelId){
		$rooms = new Rooms();
		$rows = $rooms->dao->getData("`roomId`='$roomId' AND `hotelId`='$hotelId'");
		$rooms->init($rows[0]);
		return $rooms;
	}


	/**
	 * Load all records of Rooms uniquely by its foreign keys:
	 * roomTypeCode
	 * @param roomTypeCode foreign key
	 * @return array of Instance of {@link Rooms}
	 */
	public static function loadByFKRoomtypecode($roomTypeCode){
		$rooms = new Rooms();
		$rows = $rooms->dao->getData("`roomTypeCode`='$roomTypeCode'");
		$roomss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Rooms();
			$d->init($rows[$index]);
			array_push($roomss,$d);
		}
		return $roomss;
	}


	/**
	 * Load all records of Rooms uniquely by its foreign keys:
	 * hotelId
	 * @param hotelId foreign key
	 * @return array of Instance of {@link Rooms}
	 */
	public static function loadByFKHotelid($hotelId){
		$rooms = new Rooms();
		$rows = $rooms->dao->getData("`hotelId`='$hotelId'");
		$roomss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Rooms();
			$d->init($rows[$index]);
			array_push($roomss,$d);
		}
		return $roomss;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("roomId"=>$this->roomId, "roomFloor"=>$this->roomFloor, "roomFloorCount"=>$this->roomFloorCount, "hotelId"=>$this->hotelId, "roomTypeCode"=>$this->roomTypeCode, "additionalNotes"=>$this->additionalNotes);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("roomId"=>$this->roomId, "roomFloor"=>$this->roomFloor, "roomFloorCount"=>$this->roomFloorCount, "hotelId"=>$this->hotelId, "roomTypeCode"=>$this->roomTypeCode, "additionalNotes"=>$this->additionalNotes);
		$where = "`roomId`='$roomId' AND `hotelId`='$hotelId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['roomId'])){
			$this->roomId = $_POST['roomId'];
		}
		if (isset($_POST['roomFloor'])){
			$this->roomFloor = $_POST['roomFloor'];
		}
		if (isset($_POST['roomFloorCount'])){
			$this->roomFloorCount = $_POST['roomFloorCount'];
		}
		if (isset($_POST['hotelId'])){
			$this->hotelId = $_POST['hotelId'];
		}
		if (isset($_POST['roomTypeCode'])){
			$this->roomTypeCode = $_POST['roomTypeCode'];
		}
		if (isset($_POST['additionalNotes'])){
			$this->additionalNotes = $_POST['additionalNotes'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['roomId'])){
			$this->roomId = $_GET['roomId'];
		}
		if (isset($_GET['roomFloor'])){
			$this->roomFloor = $_GET['roomFloor'];
		}
		if (isset($_GET['roomFloorCount'])){
			$this->roomFloorCount = $_GET['roomFloorCount'];
		}
		if (isset($_GET['hotelId'])){
			$this->hotelId = $_GET['hotelId'];
		}
		if (isset($_GET['roomTypeCode'])){
			$this->roomTypeCode = $_GET['roomTypeCode'];
		}
		if (isset($_GET['additionalNotes'])){
			$this->additionalNotes = $_GET['additionalNotes'];
		}
	}


	/**
	 * Returns the value from the database field roomId.
	 * In the database the field roomId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRoomId(){
		return $this->roomId;
	}


	/**
	 * Set the value from the database field roomId.
	 * In the database the field roomId is of type int.
	 * The database field is NOT nullable.
	 * @param roomId String with the value for the field to be set
	 */
	public function setRoomId($roomId){
		$this->roomId = $roomId;
	}


	/**
	 * Returns the value from the database field roomFloor.
	 * In the database the field roomFloor is of type int.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getRoomFloor(){
		return $this->roomFloor;
	}


	/**
	 * Set the value from the database field roomFloor.
	 * In the database the field roomFloor is of type int.
	 * The database field is  nullable.
	 * @param roomFloor String with the value for the field to be set
	 */
	public function setRoomFloor($roomFloor){
		$this->roomFloor = $roomFloor;
	}


	/**
	 * Returns the value from the database field roomFloorCount.
	 * In the database the field roomFloorCount is of type int.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getRoomFloorCount(){
		return $this->roomFloorCount;
	}


	/**
	 * Set the value from the database field roomFloorCount.
	 * In the database the field roomFloorCount is of type int.
	 * The database field is  nullable.
	 * @param roomFloorCount String with the value for the field to be set
	 */
	public function setRoomFloorCount($roomFloorCount){
		$this->roomFloorCount = $roomFloorCount;
	}


	/**
	 * Returns the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getHotelId(){
		return $this->hotelId;
	}


	/**
	 * Set the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @param hotelId String with the value for the field to be set
	 */
	public function setHotelId($hotelId){
		$this->hotelId = $hotelId;
	}


	/**
	 * Returns the value from the database field roomTypeCode.
	 * In the database the field roomTypeCode is of type varchar.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRoomTypeCode(){
		return $this->roomTypeCode;
	}


	/**
	 * Set the value from the database field roomTypeCode.
	 * In the database the field roomTypeCode is of type varchar.
	 * The database field is NOT nullable.
	 * @param roomTypeCode String with the value for the field to be set
	 */
	public function setRoomTypeCode($roomTypeCode){
		if(strlen($roomTypeCode) > 10) throw new Exception("roomTypeCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($roomTypeCode)." characters.");
		$this->roomTypeCode = $roomTypeCode;
	}


	/**
	 * Returns the value from the database field additionalNotes.
	 * In the database the field additionalNotes is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getAdditionalNotes(){
		return $this->additionalNotes;
	}


	/**
	 * Set the value from the database field additionalNotes.
	 * In the database the field additionalNotes is of type varchar.
	 * The database field is  nullable.
	 * @param additionalNotes String with the value for the field to be set
	 */
	public function setAdditionalNotes($additionalNotes){
		if(strlen($additionalNotes) > 45) throw new Exception("additionalNotes does not allow strings longer than 45 characters. The submitted string contains ".strlen($additionalNotes)." characters.");
		$this->additionalNotes = $additionalNotes;
	}


	/**
	 * Returns an object array containing all linked Roomfacilities objects.
	 * A One to Many(1:n) relation exists between the Rooms and the Roomfacilities.
	 * @return Roomfacilities[] Array of Roomfacilities instances
	 */
	public function getRoomfacilitiess(){
	if($this->roomfacilitiesArray == null){
			$this->roomfacilitiesArray = array();
			$temproomfacilities = new Roomfacilities();
			$dataRowsTemp = $temproomfacilities->getData("`roomId` = '$this->roomId'");
			foreach($dataRowsTemp as $dataRow){
				$tempRoomfacilities = new Roomfacilities();
				$tempRoomfacilities->init($dataRow);
				array_push($this->roomfacilitiesArray , $tempRoomfacilities);
			}
		}
		return $this->roomfacilitiesArray;
	}


	/**
	 * Returns an object array containing all linked Roombookings objects.
	 * A One to Many(1:n) relation exists between the Rooms and the Roombookings.
	 * @return Roombookings[] Array of Roombookings instances
	 */
	public function getRoombookingss(){
	if($this->roombookingsArray == null){
			$this->roombookingsArray = array();
			$temproombookings = new Roombookings();
			$dataRowsTemp = $temproombookings->getData("`roomId` = '$this->roomId'");
			foreach($dataRowsTemp as $dataRow){
				$tempRoombookings = new Roombookings();
				$tempRoombookings->init($dataRow);
				array_push($this->roombookingsArray , $tempRoombookings);
			}
		}
		return $this->roombookingsArray;
	}


	/**
	 * Set links to related Roomfacilities instances. Existing links will be overwritten
	 * @param roomfacilitiesArray array of Roomfacilities instances to be linked to this object instance
	 */
	public function setRoomfacilitiess($roomfacilitiesArray){
		foreach($roomfacilitiesArray as $roomfacilities)
			$roomfacilities->roomId = $this->roomId;
		$this->roomfacilitiesArray = $roomfacilitiesArray;
	}


	/**
	 * Add a link to object of type Roomfacilities
	 * @param roomfacilities instance of Roomfacilities to be linked to this object instance
	 */
	public function addRoomfacilities($roomfacilities){
		$roomfacilities->roomId = $this->roomId;
		if($this->roomfacilitiesArray == null) $this->roomfacilitiesArray = array();
		array_push($this->roomfacilitiesArray, $roomfacilities);
	}


	/**
	 * Set links to related Roombookings instances. Existing links will be overwritten
	 * @param roombookingsArray array of Roombookings instances to be linked to this object instance
	 */
	public function setRoombookingss($roombookingsArray){
		foreach($roombookingsArray as $roombookings)
			$roombookings->roomId = $this->roomId;
		$this->roombookingsArray = $roombookingsArray;
	}


	/**
	 * Add a link to object of type Roombookings
	 * @param roombookings instance of Roombookings to be linked to this object instance
	 */
	public function addRoombookings($roombookings){
		$roombookings->roomId = $this->roomId;
		if($this->roombookingsArray == null) $this->roombookingsArray = array();
		array_push($this->roombookingsArray, $roombookings);
	}


	/**
	 * Returns an instance of the linked Hotels object.
	 * A One to Many (1:n) relation exists between the Rooms and the Hotels table.
	 * @return Hotels the linked instance of Hotels
	 */
	public function getHotels(){
		if($this->hotels == null){
			$this->hotels = Hotels::loadUnique($this->hotelId);
		}
		return $this->hotels;
	}


	/**
	 * Set a link to a related Hotels instance
	 * @param targetObjectInstanceName instance of Hotels to be linked to this object instance
	 */
	public function setHotels($hotels){
		$hotels->hotelId = $this->hotelId;
		$this->hotels = $hotels;
	}


	/**
	 * Returns an instance of the linked Roomtypes object.
	 * A One to One(1:1) relation exists between the Roomtypes and the Rooms.
	 * @return Roomtypes the linked instance of Roomtypes
	 */
	public function getRoomtypes(){
		if($this->roomtypes == null){
			$this->roomtypes = Roomtypes::loadUnique($this->roomTypeCode);
		}
		return $this->roomtypes;
	}


	/**
	 * Set a link to a related Roomtypes instance
	 * @param roomtypes instance of Roomtypes to be linked to this object instance
	 */
	public function setRoomtypes($roomtypes){
		$roomtypes->roomTypeCode = $this->roomTypeCode;
		$this->roomtypes = $roomtypes;
	}
}
?>